/**
 * Created by enixjin on 3/6/17.
 */
import {Component, ElementRef, ViewChild} from "@angular/core";
import {ActivatedRoute, Router} from "@angular/router";
import {BaseAuthenticateComponent} from "../../shared/component/baseAuthenticate.component";
import {WeUIDialog} from "angular4-weui";
import {DialogService} from "../../service/dialogService";

@Component({
    selector: 'app-dashboard',
    templateUrl: 'dashboard.component.html'
})
export class DashboardComponent extends BaseAuthenticateComponent {
    @ViewChild('sendMsg') sendMsg: WeUIDialog;
    activeIndex: number;

    constructor(protected a_router: Router, public element: ElementRef,
                public route: ActivatedRoute, public _dialogService: DialogService) {
        super(a_router, element, route);
        this._dialogService.dialog$.subscribe((result) => {

            for (const key in result.dialogOption) {
                this.sendMsg[key] = result.dialogOption[key];
            }

            if (result.callback) {
                this.sendMsg.show().then(() => {
                    result.callback();
                }, () => {
                    // nothing to do when click cancel
                });
            } else {
                this.sendMsg.show();
            }
        });

    }

}
